package com.cf.user.login.service;

import com.cf.crud.service.AbsBaseService;
import com.cf.id.SnowflakeId;
import com.cf.user.login.dao.ThirdPartUserDao;
import com.cf.user.login.model.ThirdPartUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * game-server-ThirdPartUser
 *
 * @author <a href="2428922347@qq.com">Zhu mingming</a>
 * @info
 * @since 2018/6/13 上午 09:55
 */
@Slf4j
public class ThirdPartUserServiceImpl extends AbsBaseService<ThirdPartUser, ThirdPartUserDao> implements UserPartService {

    @Autowired
    private SnowflakeId id;

    @Autowired
    private ThirdPartUserDao thirdPartUserDao;

    @Override
    public ThirdPartUser findThirdPartUser(String channel, String unionId) {
        return thirdPartUserDao.selectByUnionId(channel, unionId);
    }

    @Override
    public ThirdPartUser addThirdUser(long userId, String openId, String unionId, String channel) {
        ThirdPartUser thirdPartUser = new ThirdPartUser();
        thirdPartUser.setOpenId(openId);
        thirdPartUser.setUnionId(unionId);
        thirdPartUser.setId((id.nextId()));
        thirdPartUser.setUserId(userId);
        thirdPartUser.setChannel(channel);
        thirdPartUserDao.insert(thirdPartUser);
        return thirdPartUser;
    }


    @Override
    public Class getTargetClass() {
        return ThirdPartUser.class;
    }
}
